<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>respondingchannel_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_messaging_respondingchannel_test.js.html">respondingchannel_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2012 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.messaging.RespondingChannelTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.messaging.RespondingChannelTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.messaging.RespondingChannel&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.MockControl&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line21"></a>goog.require(&#39;goog.testing.messaging.MockMessageChannel&#39;);
<a name="line22"></a>
<a name="line23"></a>var CH1_REQUEST = {&#39;request&#39;: &#39;quux1&#39;};
<a name="line24"></a>var CH2_REQUEST = {&#39;request&#39;: &#39;quux2&#39;};
<a name="line25"></a>var CH1_RESPONSE = {&#39;response&#39;: &#39;baz1&#39;};
<a name="line26"></a>var CH2_RESPONSE = {&#39;response&#39;: &#39;baz2&#39;};
<a name="line27"></a>var SERVICE_NAME = &#39;serviceName&#39;;
<a name="line28"></a>
<a name="line29"></a>var mockControl;
<a name="line30"></a>var ch1;
<a name="line31"></a>var ch2;
<a name="line32"></a>var respondingCh1;
<a name="line33"></a>var respondingCh2;
<a name="line34"></a>
<a name="line35"></a>function setUp() {
<a name="line36"></a>  mockControl = new goog.testing.MockControl();
<a name="line37"></a>
<a name="line38"></a>  ch1 = new goog.testing.messaging.MockMessageChannel(mockControl);
<a name="line39"></a>  ch2 = new goog.testing.messaging.MockMessageChannel(mockControl);
<a name="line40"></a>
<a name="line41"></a>  respondingCh1 = new goog.messaging.RespondingChannel(ch1);
<a name="line42"></a>  respondingCh2 = new goog.messaging.RespondingChannel(ch2);
<a name="line43"></a>}
<a name="line44"></a>
<a name="line45"></a>function tearDown() {
<a name="line46"></a>  respondingCh1.dispose();
<a name="line47"></a>  respondingCh2.dispose();
<a name="line48"></a>  mockControl.$verifyAll();
<a name="line49"></a>}
<a name="line50"></a>
<a name="line51"></a>function testSendWithSignature() {
<a name="line52"></a>  // 1 to 2 and back.
<a name="line53"></a>  var message1Ch1Request = {&#39;data&#39;: CH1_REQUEST,
<a name="line54"></a>    &#39;signature&#39;: 0};
<a name="line55"></a>  var message1Ch2Response = {&#39;data&#39;: CH2_RESPONSE,
<a name="line56"></a>    &#39;signature&#39;: 0};
<a name="line57"></a>  var message2Ch1Request = {&#39;data&#39;: CH1_REQUEST,
<a name="line58"></a>    &#39;signature&#39;: 1};
<a name="line59"></a>  var message2Ch2Response = {&#39;data&#39;: CH2_RESPONSE,
<a name="line60"></a>    &#39;signature&#39;: 1};
<a name="line61"></a>  // 2 to 1 and back.
<a name="line62"></a>  var message3Ch2Request = {&#39;data&#39;: CH2_REQUEST,
<a name="line63"></a>    &#39;signature&#39;: 0};
<a name="line64"></a>  var message3Ch1Response = {&#39;data&#39;: CH1_RESPONSE,
<a name="line65"></a>    &#39;signature&#39;: 0};
<a name="line66"></a>  var message4Ch2Request = {&#39;data&#39;: CH2_REQUEST,
<a name="line67"></a>    &#39;signature&#39;: 1};
<a name="line68"></a>  var message4Ch1Response = {&#39;data&#39;: CH1_RESPONSE,
<a name="line69"></a>    &#39;signature&#39;: 1};
<a name="line70"></a>
<a name="line71"></a>  // 1 to 2 and back.
<a name="line72"></a>  ch1.send(
<a name="line73"></a>      &#39;public:&#39; + SERVICE_NAME,
<a name="line74"></a>      message1Ch1Request);
<a name="line75"></a>  ch2.send(
<a name="line76"></a>      &#39;private:mics&#39;,
<a name="line77"></a>      message1Ch2Response);
<a name="line78"></a>  ch1.send(
<a name="line79"></a>      &#39;public:&#39; + SERVICE_NAME,
<a name="line80"></a>      message2Ch1Request);
<a name="line81"></a>  ch2.send(
<a name="line82"></a>      &#39;private:mics&#39;,
<a name="line83"></a>      message2Ch2Response);
<a name="line84"></a>
<a name="line85"></a>  // 2 to 1 and back.
<a name="line86"></a>  ch2.send(
<a name="line87"></a>      &#39;public:&#39; + SERVICE_NAME,
<a name="line88"></a>      message3Ch2Request);
<a name="line89"></a>  ch1.send(
<a name="line90"></a>      &#39;private:mics&#39;,
<a name="line91"></a>      message3Ch1Response);
<a name="line92"></a>  ch2.send(
<a name="line93"></a>      &#39;public:&#39; + SERVICE_NAME,
<a name="line94"></a>      message4Ch2Request);
<a name="line95"></a>  ch1.send(
<a name="line96"></a>      &#39;private:mics&#39;,
<a name="line97"></a>      message4Ch1Response);
<a name="line98"></a>
<a name="line99"></a>  mockControl.$replayAll();
<a name="line100"></a>
<a name="line101"></a>  var hasInvokedCh1 = false;
<a name="line102"></a>  var hasInvokedCh2 = false;
<a name="line103"></a>  var hasReturnedFromCh1 = false;
<a name="line104"></a>  var hasReturnedFromCh2 = false;
<a name="line105"></a>
<a name="line106"></a>  var serviceCallback1 = function(message) {
<a name="line107"></a>    hasInvokedCh1 = true;
<a name="line108"></a>    assertObjectEquals(CH2_REQUEST, message);
<a name="line109"></a>    return CH1_RESPONSE;
<a name="line110"></a>  };
<a name="line111"></a>
<a name="line112"></a>  var serviceCallback2 = function(message) {
<a name="line113"></a>    hasInvokedCh2 = true;
<a name="line114"></a>    assertObjectEquals(CH1_REQUEST, message);
<a name="line115"></a>    return CH2_RESPONSE;
<a name="line116"></a>  };
<a name="line117"></a>
<a name="line118"></a>  var invocationCallback1 = function(message) {
<a name="line119"></a>    hasReturnedFromCh2 = true;
<a name="line120"></a>    assertObjectEquals(CH2_RESPONSE, message);
<a name="line121"></a>  };
<a name="line122"></a>
<a name="line123"></a>  var invocationCallback2 = function(message) {
<a name="line124"></a>    hasReturnedFromCh1 = true;
<a name="line125"></a>    assertObjectEquals(CH1_RESPONSE, message);
<a name="line126"></a>  };
<a name="line127"></a>
<a name="line128"></a>  respondingCh1.registerService(SERVICE_NAME, serviceCallback1);
<a name="line129"></a>  respondingCh2.registerService(SERVICE_NAME, serviceCallback2);
<a name="line130"></a>
<a name="line131"></a>  respondingCh1.send(SERVICE_NAME, CH1_REQUEST, invocationCallback1);
<a name="line132"></a>  ch2.receive(&#39;public:&#39; + SERVICE_NAME, message1Ch1Request);
<a name="line133"></a>  ch1.receive(&#39;private:mics&#39;, message1Ch2Response);
<a name="line134"></a>
<a name="line135"></a>  respondingCh1.send(SERVICE_NAME, CH1_REQUEST, invocationCallback1);
<a name="line136"></a>  ch2.receive(&#39;public:&#39; + SERVICE_NAME, message2Ch1Request);
<a name="line137"></a>  ch1.receive(&#39;private:mics&#39;, message2Ch2Response);
<a name="line138"></a>
<a name="line139"></a>  respondingCh2.send(SERVICE_NAME, CH2_REQUEST, invocationCallback2);
<a name="line140"></a>  ch1.receive(&#39;public:&#39; + SERVICE_NAME, message3Ch2Request);
<a name="line141"></a>  ch2.receive(&#39;private:mics&#39;, message3Ch1Response);
<a name="line142"></a>
<a name="line143"></a>  respondingCh2.send(SERVICE_NAME, CH2_REQUEST, invocationCallback2);
<a name="line144"></a>  ch1.receive(&#39;public:&#39; + SERVICE_NAME, message4Ch2Request);
<a name="line145"></a>  ch2.receive(&#39;private:mics&#39;, message4Ch1Response);
<a name="line146"></a>
<a name="line147"></a>  assertTrue(
<a name="line148"></a>      hasInvokedCh1 &amp;&amp;
<a name="line149"></a>      hasInvokedCh2 &amp;&amp;
<a name="line150"></a>      hasReturnedFromCh1 &amp;&amp;
<a name="line151"></a>      hasReturnedFromCh2);
<a name="line152"></a>}
</pre>


</body>
</html>
